<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<%@ page import="database_layer.*" %>
<%@ page import="java.util.*"%>
<%@ page import="processing_layer.*" %>
<%@ page import="interface_layer.ErrorHandler" %>
<%@ page errorPage="exceptionPage.jsp" %>
<%-- 
	This JSP handles the user details update form. It has its own JS code which
	checks if the user has inserted proper values.
 --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255"/>
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/detailsUpdateFormValidation.js"></script>
<title>User details update</title>
</head>
<body>
<jsp:include page="header_part_1.html"/>
            <div id="templatemo_menu">
                <ul>
                    <li><a href="index.jsp">Home</a></li>
                    <li><a href="about.jsp">About Us</a></li>
<%
                    	String username = (String) session.getAttribute("username");
                        if (null != username)
                        {
%>
                            <li><a href="userPage.jsp" class="current">Your profile</a></li>
						    <li><a href="allCourses.jsp">Courses</a></li>
                    		<li><a href="allUsers.jsp">Users</a></li>
<%
                        }
%>
                </ul>    	
            </div> <!-- end of templatemo_menu -->
<jsp:include page="header_part_2.html"/>
<div id="content">
<%
    String userType = (String) session.getAttribute("userType");
    
    if (null == username)
    {
    	ErrorHandler.parseForErrors(Common.UNAUTHORIZED_OPERATION, response, null);
    	return;
    }
    
    else
    {
    	User userDetails = QueryDispatcher.getUserDetails(username);
    	if (null == userDetails)
    	{
    		ErrorHandler.parseForErrors(Common.INTERNAL_DB_ERROR, response, null);
    		return;
    	}
    	else if (null == userDetails.username)
    	{
    		ErrorHandler.parseForErrors(Common.ENTRY_DOESNT_EXIST, response, null);
    		return;    		
    	}
    	else
    	{
%>
    		<i>Please check the fields you're planning to change... </i><br/><br/>
    		<form name="updateForm" id="updateForm" method="post" action="UpdateUser" onsubmit="return validityCheck()">
    		
    		<label for="change_password_value"><b>Password</b> </label> <br/>
			<input type="checkbox" id="change_password" name="change_password" onclick="passwordBoxClick()"/>
			<input type="password" id="change_password_value" name="change_password_value" value="<%= userDetails.password %>"/> <br/>
			<label for="change_password_confirm_value">Confirm Password </label> <br/>
			<input type="checkbox" id="change_password_confirm" name="change_password_confirm" disabled="disabled"/>
			<input type="password" id="change_password_confirm_value" name="change_password_confirm_value" value="<%= userDetails.password %>"/> <br/>
			
			<label for="change_first_name_value"><b>First name</b> </label> <br/>
			<input type="checkbox" id="change_first_name" name="change_first_name"/>
			<input type="text" id="change_first_name_value" name="change_first_name_value" value="<%= userDetails.firstName %>"/> <br/>
			
			<label for="change_last_name_value"><b>Last name</b> </label> <br/>
			<input type="checkbox" id="change_last_name" name="change_last_name"/>
			<input type="text" id="change_last_name_value" name="change_last_name_value" value="<%= userDetails.lastName %>"/> <br/>
			
			<label for="change_phone_number_value"><b>Phone </b></label> <br/>
			<input type="checkbox" id="change_phone_number" name="change_phone_number"/>
			<input type="text" id="change_phone_number_value" name="change_phone_number_value" value="<%= userDetails.phone %>"/> <br/>
			
			<label for="change_adress_value"><b>Address</b> </label> <br/>
			<input type="checkbox" id="change_address" name="change_address"/>
			<input type="text" id="change_address_value" name="change_address_value" value="<%= userDetails.address %>"/> <br/>
            <br/>
            <input type="submit" value="Update details"/>
            </form>
<%
    	}
    }
%>
</div>
<jsp:include page="sidebar.jsp"/>
<jsp:include page="footer.html"/>
</body>
</html>